package response

import (
	"longmen/server/internal/services/nami/services/esport/csgo"
	"longmen/server/pkg/db/mysql/models/models_esports"
)

type (
	TeamApiResponse struct {
		Code  int `json:"code"`
		Query struct {
			Limit int    `json:"limit"`
			Type  string `json:"type"`
			Total int    `json:"total"`
			ID    int    `json:"id"`
			MinID int    `json:"min_id"`
			MaxID int    `json:"max_id"`
		} `json:"query"`
		Results []Team `json:"results"`
	}
	Team struct {
		ID      int    `json:"id"`
		NameEn  string `json:"name_en"`
		NameZh  string `json:"name_zh"`
		AbbrEn  string `json:"abbr_en"`
		AbbrZh  string `json:"abbr_zh"`
		Logo    string `json:"logo"`
		Country struct {
			ID int `json:"id"`
		} `json:"country"`
		Ranking int `json:"ranking"`
		Region  struct {
			ID int `json:"id"`
		} `json:"region"`
		CreateTime    int    `json:"create_time"`
		TotalEarnings string `json:"total_earnings"`
		UpdatedAt     int    `json:"updated_at"`
	}
)

func (t Team) Get() models_esports.CsgoTeam {
	return models_esports.CsgoTeam{
		ID:            t.ID,
		NameEn:        t.NameEn,
		NameZh:        t.NameZh,
		AbbrEn:        t.AbbrEn,
		AbbrZh:        t.AbbrZh,
		Logo:          t.Logo,
		CreateTime:    t.CreateTime,
		RegionID:      t.Region.ID,
		TotalEarnings: t.TotalEarnings,
		CountryId:     t.Country.ID,
		UpdatedAt:     t.UpdatedAt,
	}
}

func (t TeamApiResponse) Interfaces() []csgo.InsertTeamInterface {
	records := make([]csgo.InsertTeamInterface, 0)
	for _, result := range t.Results {
		records = append(records, result)
	}
	return records
}
